package com.huifaapp.mall.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.FileIOUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.FutureTarget;
import com.bumptech.glide.request.Request;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.huifaapp.mall.APP;
import com.huifaapp.mall.R;
import com.huifaapp.mall.afinal.Constants;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.api.ObserverCallback;
import com.huifaapp.mall.bean.JDlianjie;
import com.huifaapp.mall.bean.ShareImageBean;
import com.huifaapp.mall.bean.SpecialBean;
import com.huifaapp.mall.bean.TodaysSelectionBean;
import com.huifaapp.mall.dialogs.LoadingDialog;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.Contig;
import com.huifaapp.mall.uitils.ShareUtils;
import com.huifaapp.mall.uitils.UtilsImage;
import com.kepler.jd.Listener.LoginListener;
import com.kepler.jd.login.KeplerApiManager;
import com.kepler.jd.sdk.exception.KeplerBufferOverflowException;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

import static com.huifaapp.mall.afinal.Constants.savePath;

/**
 * Created by Administrator on 2018/1/30.
 */

public class Specialactivity extends AppCompatActivity{

    public static Map<Integer, Boolean> hmap;
    private ImageView iv_Speclia_back;
    private TextView tv_Speclia_title;
    private PullToRefreshGridView gv_special_pull;
    private PullToRefreshListView lv_special_pull;
    List<SpecialBean.DataBean.ListBean> listb;
    List<SpecialBean.DataBean.ListBean> listblist;
    SpecialGridViewAdapter adapter;
    ImageView iv_speclia_add;
    private ImageView iv_share_fubiao_share;
    ArrayList<String> idlist = new ArrayList<>();
    ArrayList<String> idlistlv = new ArrayList<>();
    private static final int SHARET_WXHY = 517;
    private ImageView iv_Grid_image;
    boolean flag=true;
    private SpecialListViewAdapter adapterlist;
    private int lvgv=0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.special_activity);
        hmap = new HashMap<>();
        iv_Speclia_back= (ImageView) findViewById(R.id.iv_Speclia_back);
        tv_Speclia_title= (TextView) findViewById(R.id.tv_Speclia_title);
        gv_special_pull= (PullToRefreshGridView) findViewById(R.id.gv_special_pull);
        lv_special_pull= (PullToRefreshListView) findViewById(R.id.lv_special_pull);
        iv_speclia_add= (ImageView)findViewById(R.id.iv_speclia_add);
        iv_share_fubiao_share= (ImageView) findViewById(R.id.iv_share_fubiao_share);
        iv_Grid_image= (ImageView) findViewById(R.id.iv_Grid_image);
        iv_Grid_image.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if(flag){
                    iv_Grid_image.setImageResource(R.drawable.btn_blue_qiehuan_1);
                    lv_special_pull.setVisibility(View.VISIBLE);
                    gv_special_pull.setVisibility(View.GONE);
                    lvgv = 1;
                    flag=false;
                }else{
                    iv_Grid_image.setImageResource(R.drawable.btn_icon_leibiao);
                    lv_special_pull.setVisibility(View.GONE);
                    gv_special_pull.setVisibility(View.VISIBLE);
                    lvgv = 0;
                    flag=true;
                }

            }
        });
        if(SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            iv_share_fubiao_share.setVisibility(View.VISIBLE);
        }else{
            iv_share_fubiao_share.setVisibility(View.GONE);
        }
        iv_share_fubiao_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Specialactivity.this,"分享",Toast.LENGTH_SHORT).show();
                if(lvgv == 0){
                Log.e("数据Toady", Contig.checkedIndexs + "-=====Contig.checkedIndex===id");
                if (Contig.checkedIndexs.size() == 0) {
                    Toast.makeText(Specialactivity.this, "没有选择，请选择再分享！", Toast.LENGTH_SHORT).show();
                } else {
                    for (int i = 0; i < Contig.checkedIndexs.size(); i++)
                        idlist.add(listb.get(Contig.checkedIndexs.get(i)).getId());

                    Log.e("数据Toady", idlist + "-===========id");


                    StringBuffer permission = new StringBuffer();
                    for (int i = 0; i < idlist.size(); i++) {
                        if (i == 0) {
                            permission.append(idlist.get(i));
                        } else {
                            permission.append("," + idlist.get(i));
                        }
                        Contig.listidid.add(idlist.get(i));

                    }
//                    LoadStoreList(0, 0, Contig.listidid);

                    ApiManager
                            .getInstance()
                            .getApiServer()
                            .getShareImage(SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN), AUniqueIdentifier.getDeviceId(Specialactivity.this), permission.toString())
                            .compose(ApiManager.<ShareImageBean>handlResult())
                            .subscribe(new ObserverCallback<ShareImageBean>(Specialactivity.this) {
                                @Override
                                protected void onSuccessful(ShareImageBean resp) {

                                    saveImage(resp.getPoster(), resp.getFailure(), SHARET_WXHY);
                                    if (Contig.checkedIndexs.size() > 0) {
                                        for (int a = 0; a < Contig.checkedIndexs.size(); a++) {
                                            Contig.ShareList.add(listb.get(Contig.checkedIndexs.get(a)).getId());
                                        }
                                    }
                                    adapter = new SpecialGridViewAdapter(Specialactivity.this, listb);
                                    gv_special_pull.setAdapter(adapter);

                                }

                                @Override
                                protected void onError(String code, String errMsg) {
                                    ToastUtils.showShortSafe(errMsg);
                                }
                            });
                    idlist.clear();
                }
                }else if(lvgv == 1) {
                    Log.e("数据Toady", Contig.checkedIndexlist + "-=====Contig.checkedIndex===id");
                    if (Contig.checkedIndexlist.size() == 0) {
                        Toast.makeText(Specialactivity.this, "没有选择，请选择再分享！", Toast.LENGTH_SHORT).show();
                    } else {
                        for (int i = 0; i < Contig.checkedIndexlist.size(); i++)
                            idlistlv.add(listblist.get(Contig.checkedIndexlist.get(i)).getId());

                        Log.e("数据Toady", idlistlv + "-===========id");


                        StringBuffer permission = new StringBuffer();
                        for (int i = 0; i < idlistlv.size(); i++) {
                            if (i == 0) {
                                permission.append(idlistlv.get(i));
                            } else {
                                permission.append("," + idlistlv.get(i));
                            }
                            Contig.listididlist.add(idlistlv.get(i));

                        }
//                    LoadStoreList(0, 0, Contig.listidid);

                        ApiManager
                                .getInstance()
                                .getApiServer()
                                .getShareImage(SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN), AUniqueIdentifier.getDeviceId(Specialactivity.this), permission.toString())
                                .compose(ApiManager.<ShareImageBean>handlResult())
                                .subscribe(new ObserverCallback<ShareImageBean>(Specialactivity.this) {
                                    @Override
                                    protected void onSuccessful(ShareImageBean resp) {

                                        saveImage(resp.getPoster(), resp.getFailure(), SHARET_WXHY);
                                        if (Contig.checkedIndexlist.size() > 0) {
                                            for (int a = 0; a < Contig.checkedIndexlist.size(); a++) {
                                                Contig.ShareListlv.add(listblist.get(Contig.checkedIndexlist.get(a)).getId());
                                            }
                                        }
                                        adapterlist = new SpecialListViewAdapter(Specialactivity.this, listblist);
                                        lv_special_pull.setAdapter(adapterlist);

                                    }

                                    @Override
                                    protected void onError(String code, String errMsg) {
                                        ToastUtils.showShortSafe(errMsg);
                                    }
                                });
                        idlistlv.clear();
                    }
                }
            }
        });
        iv_Speclia_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        lv_special_pull.setMode(PullToRefreshBase.Mode.BOTH);//两端刷新
        lv_special_pull.setSelected(true);
        lv_special_pull.setScrollingWhileRefreshingEnabled(true);

        loadSpeciallist(0, 0);
        lv_special_pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                loadSpeciallist(0, 0);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                loadSpeciallist(1, listblist.size()/10);
            }
        });


        new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                lv_special_pull.setRefreshing(true);
                return false;
            }
        }).sendEmptyMessageDelayed(0, 200);
        gv_special_pull.setMode(PullToRefreshBase.Mode.BOTH);//两端刷新
        gv_special_pull.setSelected(true);
        gv_special_pull.setScrollingWhileRefreshingEnabled(true);

        loadSpecial(0, 0);
        gv_special_pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
                loadSpecial(0, 0);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {

                int lsize=listb.size();

                loadSpecial(1, lsize/10);
            }
        });


        new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                gv_special_pull.setRefreshing(true);
                return false;
            }
        }).sendEmptyMessageDelayed(0, 200);

    }
    private void saveImage(List<String> imageUrls, final String cconten, final int type) {

        Log.v("shiran", "------------saveImage------------");

        final LoadingDialog dialog = new LoadingDialog(Specialactivity.this);
        dialog.setContent("正在生成图片请稍后");


        Observable.just(imageUrls)
                .map(new Function<List<String>, List<String>>() {

                    @Override
                    public List<String> apply(List<String> list) throws Exception {

                        List<String> paths = new ArrayList<String>();
                        for (String s : list) {
                            FutureTarget<File> future = Glide.with(APP.getInstance())
                                    .load(s)
                                    .downloadOnly(500, 500);
                            File cacheFile = future.get();
                            String uuid = UUID.randomUUID().toString();
                            FileIOUtils.writeFileFromIS(savePath + uuid + ".jpg", new FileInputStream(cacheFile));
                            String pat = savePath + uuid + ".jpg";
                            paths.add(pat);

                        }


                        return paths;
                    }
                }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<String>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        if (dialog != null && !dialog.isShowing()) {
                            dialog.show();
                        }
                    }

                    @Override
                    public void onNext(List<String> value) {
                        LogUtils.e(value);
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }

                        switch (type) {
                            case SHARET_WXHY:


                                ShareUtils.sharePicToFriendNoSDK(Specialactivity.this, value);
//                                        ClipboardUtils.copyText(cconten);
//                                        ToastUtils.showShortSafe("内容已复制!");
                                break;
//                            case SHARET_WXPYQ:
//                                ShareUtils.share9PicsToWXCircle(getActivity(), "", value);
//                                break;
                            default:

                                break;
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }
                    }

                    @Override
                    public void onComplete() {
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                            dialog.cancel();
                        }
                    }
                });

    }
    int lengthlist = 10;
    int startlist = 0;
    private void loadSpeciallist(final int downorup, int starts){
        String id=getIntent().getStringExtra("id");
        String urlmarket=getIntent().getStringExtra("urlmarket");
        if (downorup == 0) {
            lengthlist = 10;
            startlist = 0;
        } else if (downorup == 1) {
            lengthlist = 10;
            startlist = starts;
        }
        String url =urlmarket +"?id="+id+ "&start=" + startlist + "&length=" + lengthlist;

        Log.e("WEB", "路径--" + url);
        HttpUtils http = new HttpUtils();
        //http://www.jhjvip.cn:8081/market/mobile/jd/index?
        http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onLoading(long total, long current, boolean isUploading) {
//              testTextView.setText(current + "/" + total);
                Log.e("数据", "数据-------" + current + "/" + total);
            }

            //
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
                lv_special_pull.onRefreshComplete();
                Log.e("数据123", "数据d-------" + responseInfo.result);
                try {
                    Gson gson = new Gson();
                    SpecialBean list = gson.fromJson(responseInfo.result, SpecialBean.class);
                    if (list.getCode().equals("10000")) {
                        tv_Speclia_title.setText(list.getData().getTitle());
//                       View view=View.inflate(Specialactivity.this,R.layout.image_add,null);

                        UtilsImage.uploadimageview(iv_speclia_add,list.getData().getBanner().get(0),"",Specialactivity.this);


                        if (list.getData().getList() != null && list.getData().getList().size() > 0) {


                            if (downorup == 0) {
                                listblist = list.getData().getList();
                                adapterlist = new SpecialListViewAdapter(Specialactivity.this, listblist);
                                lv_special_pull.setAdapter(adapterlist);


                            } else {

                                listblist.addAll(list.getData().getList());
                                if (listb.size() == 0) {
                                    lv_special_pull.setVisibility(View.GONE);
                                }
                                adapterlist.notifyDataSetChanged();
                                // listView.getRefreshableView().setSelection(a);
                            }
                        }
                    } else {
                        Toast.makeText(Specialactivity.this, list.getMsg(), Toast.LENGTH_SHORT).show();
                    }
                } catch (JsonSyntaxException e) {
                    Toast.makeText(Specialactivity.this, "未知错误", Toast.LENGTH_LONG).show();
                }

            }

            @Override
            public void onStart() {
            }

            @Override
            public void onFailure(HttpException error, String msg) {
                lv_special_pull.onRefreshComplete();
            }
        });
    }

    int length = 10;
    int start = 0;
   private void loadSpecial(final int downorup, int starts){
        String id=getIntent().getStringExtra("id");
       String urlmarket=getIntent().getStringExtra("urlmarket");
       if (downorup == 0) {
           length = 10;
           start = 0;
       } else if (downorup == 1) {
           length = 10;
           start = starts;
       }
       String url =urlmarket+"?id="+id+ "&start=" + start + "&length=" + length;
       Log.e("WEB", "路径--" + url);
       HttpUtils http = new HttpUtils();
       //http://www.jhjvip.cn:8081/market/mobile/jd/index?
       http.send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
           @Override
           public void onLoading(long total, long current, boolean isUploading) {
//              testTextView.setText(current + "/" + total);
               Log.e("数据", "数据-------" + current + "/" + total);
           }

           //
           @Override
           public void onSuccess(ResponseInfo<String> responseInfo) {
//                    textView.setText(responseInfo.result);
               gv_special_pull.onRefreshComplete();
               Log.e("数据123", "数据d-------" + responseInfo.result);
               try {
                   Gson gson = new Gson();
                   SpecialBean list = gson.fromJson(responseInfo.result, SpecialBean.class);
                   if (list.getCode().equals("10000")) {
                       tv_Speclia_title.setText(list.getData().getTitle());
//                       View view=View.inflate(Specialactivity.this,R.layout.image_add,null);

                       UtilsImage.uploadimageview(iv_speclia_add,list.getData().getBanner().get(0),"",Specialactivity.this);


                       if (list.getData().getList() != null && list.getData().getList().size() > 0) {


                           if (downorup == 0) {
                               listb = list.getData().getList();
                               adapter = new SpecialGridViewAdapter(Specialactivity.this, listb);
                               gv_special_pull.setAdapter(adapter);


                           } else {

                               listb.addAll(list.getData().getList());
                               if (listb.size() == 0) {
                                   gv_special_pull.setVisibility(View.GONE);
                               }
                               adapter.notifyDataSetChanged();
                               // listView.getRefreshableView().setSelection(a);
                           }
                       }
                   } else {
                       Toast.makeText(Specialactivity.this, list.getMsg(), Toast.LENGTH_SHORT).show();
                   }
               } catch (JsonSyntaxException e) {
                   Toast.makeText(Specialactivity.this, "未知错误", Toast.LENGTH_LONG).show();
               }

           }

           @Override
           public void onStart() {
           }

           @Override
           public void onFailure(HttpException error, String msg) {
               gv_special_pull.onRefreshComplete();
           }
       });
    }
}
class SpecialGridViewAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<SpecialBean.DataBean.ListBean> list;
    private IWXAPI api;
    ArrayList<String> arrayList;
    private List<Boolean> isChecked;    //每个条目是否为选中
    private List<String> numbers;       //每个条目应显示的数字
    private List<Integer> checkedIndex;   //保存选中的下标
    private List<CheckBox> checkBox;      //保存选中的checkBox
    private int maxChecked = 9;       //最多选中几个
    private int checkedNumber = 0;    //选中的个数
    //        private int length = list.size();  //条目的总长
    ArrayList<String> idlist;

    ArrayList<Integer> a = new ArrayList<>();
    int aa = 0;
    private JDlianjie jDlianjiebean;
    private String datalisnajie;
    private int location;
    private String datayouhui;

    public SpecialGridViewAdapter(Context context, List<SpecialBean.DataBean.ListBean> list) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.list = list;
        this.idlist = idlist;
// 通过WXAPIFactory工厂，获取IWXAPI的实例
        api = WXAPIFactory.createWXAPI(context, Constants.WX_APPID);
        api.registerApp(Constants.WX_APPID);
        arrayList = new ArrayList<String>();
        isChecked = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            isChecked.add(false);
        }
        numbers = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            numbers.add("");
        }
        checkedIndex = new ArrayList<>();
        checkBox = new ArrayList<>();

    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public List<SpecialBean.DataBean.ListBean> getList() {
        return list;
    }

    public SpecialGridViewAdapter setList(List<SpecialBean.DataBean.ListBean> list) {
        this.list = list;
        return this;
    }

    int ds = 0;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.item_specail_gridview, null);
            holder = new ViewHolder();
            holder.iv_item_share_todaySeletion_shopimage = (ImageView) convertView.findViewById(R.id.iv_item_share_todaySeletion_shopimage_specila);
            holder.tv_share_today_name = (TextView) convertView.findViewById(R.id.tv_share_today_name_specila);
            holder.tv_share_today_yuanprice = (TextView) convertView.findViewById(R.id.tv_share_today_yuanprice_specila);
            holder.tv_share_taday_redprice = (TextView) convertView.findViewById(R.id.tv_share_taday_redprice_spec);
            holder.tv_share_xianprice = (TextView) convertView.findViewById(R.id.tv_share_xianprice_specila);
            holder.tv_share_todaySeletion_yiqiangnum = (TextView) convertView.findViewById(R.id.tv_share_todaySeletion_yiqiangnum_specila);
            holder.tv_lijishare_btn = (TextView) convertView.findViewById(R.id.tv_lijishare_btn_specila);
            holder.tv_lijishare_btn_no = (TextView) convertView.findViewById(R.id.tv_lijishare_btn_no_specila);
            holder.cb_checked = (CheckBox) convertView.findViewById(R.id.cb_checked_share_specila);
            holder.iv_speclia_jdOryh= (ImageView) convertView.findViewById(R.id.iv_speclia_jdOryh);
            holder.ll_details_go= (LinearLayout) convertView.findViewById(R.id.ll_details_go);
            holder.tv_lijishare_btn_specila_pt= (TextView) convertView.findViewById(R.id.tv_lijishare_btn_specila_pt);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //解决RecyclerView和checkBox问题
        holder.cb_checked.setTag(position);
        if (Specialactivity.hmap.containsKey(position)) {
            holder.cb_checked.setChecked(TodaysSelectionFragment.hmap.get(position));
        } else {
            holder.cb_checked.setChecked(false);//true or false 都可以，看实际需求
        }
//        if(list.get(position).getIsHot().equals("1")){
//            holder.itme_tmall_imge_choiceness.setImageResource(R.drawable.img_blun_biaoqian_baop_1);
//        }else{
//            holder.itme_tmall_imge_choiceness.setImageResource(R.drawable.rhome_img_1);
//        }
        if(SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            holder.cb_checked.setVisibility(View.VISIBLE);
            holder.tv_lijishare_btn_specila_pt.setVisibility(View.GONE);
            holder.tv_lijishare_btn.setVisibility(View.VISIBLE);
        }else{
            holder.cb_checked.setVisibility(View.GONE);
            holder.tv_lijishare_btn_specila_pt.setVisibility(View.VISIBLE);
            holder.tv_lijishare_btn.setVisibility(View.GONE);
        }
        final SpecialBean.DataBean.ListBean bean = list.get(position);
        Log.e("数据", "positionLIST=========" + bean);
        UtilsImage.uploadimageview(holder.iv_item_share_todaySeletion_shopimage, bean.getMainImageUrl(), "", context);
        holder.tv_share_today_name.setText("\t\t\t\t" + bean.getGoodsName());
        holder.tv_share_today_yuanprice.setText("¥" + bean.getPrice());
        holder.tv_share_today_yuanprice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);
        holder.tv_share_taday_redprice.setText("降" + bean.getCouponMoney()+"元");
        holder.tv_share_xianprice.setText("" + bean.getConPrice());
        holder.tv_share_todaySeletion_yiqiangnum.setText("已抢" + bean.getTotalSales() + "件");
        if( list.get(position).getWlCommission()==0|| list.get(position).getWlCommission()==0.0|| list.get(position).getWlCommission()==0.00){
            holder.tv_lijishare_btn.setText("立即分享");
            holder.tv_lijishare_btn_no.setText("立即分享赚");
        }else {
            holder.tv_lijishare_btn.setText("立即分享赚 ¥" + bean.getWlCommission());
            holder.tv_lijishare_btn_no.setText("立即分享赚 ¥" + bean.getWlCommission());
        }
        holder.tv_lijishare_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShopYouhuiShareActivity.class);
                intent.putExtra("id", bean.getId());
                context.startActivity(intent);
                holder.tv_lijishare_btn_no.setVisibility(View.VISIBLE);
                holder.tv_lijishare_btn.setVisibility(View.GONE);

            }
        });
        if(bean.getSpuPlatform().equals("jd")){
            holder.iv_speclia_jdOryh.setImageResource(R.drawable.jingdong);
        }else if(bean.getSpuPlatform().equals("yh")){
            holder.iv_speclia_jdOryh.setImageResource(R.drawable.youhui);
        }

        holder.ll_details_go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                location = position;
                if (bean.getSpuPlatform().equals("yh")){
                    Intent intent=new Intent(context,Red_PacketActivity.class);
                    intent.putExtra("shopid",bean.getId());
                    intent.putExtra("typex","yh");
                    context.startActivity(intent);
                } else {
                    if (bean.getSpuPlatform().equals("jd")) {
                        if ("".equals(bean.getCouponMoney()+"")) {
                            initJDputong(bean.getId());
                            if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                try {
                                    KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                } catch (KeplerBufferOverflowException e) {
                                    e.printStackTrace();
                                }

                            }else {
                                final LoginListener mLoginListener = new LoginListener() {
                                    @Override
                                    public void authSuccess(Object token) {
                                        // TODO Auto-generated method stub
                                        Toast.makeText(context, token + "", Toast.LENGTH_SHORT).show();
                                        //                showToken();

                                        if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                            try {
                                                KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                            } catch (KeplerBufferOverflowException e) {
                                                e.printStackTrace();
                                            }
                                        }

                                    }

                                    @Override
                                    public void authFailed(int errorCode) {
                                        // TODO Auto-generated method stub
                                        switch (errorCode) {
                                            case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                            default:
                                                break;
                                        }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                        Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                    }
                                };
                                KeplerApiManager.getWebViewService().login((Activity) context, mLoginListener);
                            }
//                            Intent intent = new Intent(context, HtmlActivity.class);
//                            intent.putExtra("data", datalisnajie);
//                            intent.putExtra("shopid", bean.getId());
//                            context.startActivity(intent);
                        }
                        if (""!=bean.getCouponMoney()+""){
                            if (bean.getCouponMoney()==0.0){
                                Map<String,String>map=new HashMap<>();
                                map.put("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId",bean.getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(context));
                                Log.e("优惠二和一链接接口",ApiManager.BASE_NIUPAI_URL+"jd/getConUrl"+"?token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&spuId="+bean.getId()+"&appid="+AUniqueIdentifier.getDeviceId(context));
                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getConUrl").build().execute(new StringCallback() {


                                    @Override
                                    public void onError(com.squareup.okhttp.Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        Log.e("优惠二和一数据",response);
                                        Gson gson=new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            Intent intent=new Intent(context,JDred_packetActivity.class);
                                            intent.putExtra("shopid",bean.getId());
                                            context.startActivity(intent);
                                        }
                                    }
                                });

                            }else {
                                Map<String,String>map=new HashMap<>();
                                map.put("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId",bean.getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(context));

                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getConUrl").build().execute(new StringCallback() {


                                    @Override
                                    public void onError(com.squareup.okhttp.Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        Log.e("优惠二和一数据",response);
                                        Gson gson=new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            if (jDlianjiebean.getData()!=null){
                                                if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                                    try {
                                                        KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                    } catch (KeplerBufferOverflowException e) {
                                                        e.printStackTrace();
                                                    }

                                                }else {
                                                    final LoginListener mLoginListener = new LoginListener() {
                                                        @Override
                                                        public void authSuccess(Object token) {
                                                            // TODO Auto-generated method stub
                                                            Toast.makeText(context, token + "", Toast.LENGTH_SHORT).show();
                                                            //                showToken();

                                                            if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                                                try {
                                                                    KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                                } catch (KeplerBufferOverflowException e) {
                                                                    e.printStackTrace();
                                                                }
                                                            }

                                                        }

                                                        @Override
                                                        public void authFailed(int errorCode) {
                                                            // TODO Auto-generated method stub
                                                            switch (errorCode) {
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                                                default:
                                                                    break;
                                                            }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                                            Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                                        }
                                                    };
                                                    KeplerApiManager.getWebViewService().login((Activity) context, mLoginListener);
                                                }
//                                                Intent intent = new Intent(context, HtmlActivity.class);
//                                                intent.putExtra("shopid", bean.getId());
//                                                intent.putExtra("data", datayouhui);
//                                                context.startActivity(intent);

                                            }
                                        }
                                    }
                                });


                            }
                        }


                    }
                }

            }

        });
        try {


            //  不要动
            holder.cb_checked.setChecked(isChecked.get(position));
            holder.cb_checked.setText(numbers.get(position));
            holder.cb_checked.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    boolean check;
                    if (checkedNumber < maxChecked) {
                        if (!isChecked.get(position)) {
                            checkedIndex.add(position);
                            checkBox.add(holder.cb_checked);
                            checkedNumber++;
                            setText();
                        } else {
                            clearText(position, holder.cb_checked);
                        }
                        check = !isChecked.get(position);
                    } else {
                        if (checkedNumber == maxChecked && isChecked.get(position)) {
                            clearText(position, holder.cb_checked);
                        } else {
                            Toast.makeText(context, "最多只能选" + maxChecked + "个", Toast.LENGTH_SHORT).show();
                        }
                        check = false;
                    }
                    isChecked.set(position, check);
                    holder.cb_checked.setChecked(isChecked.get(position));
                }
            });

            Contig.checkedIndexs = checkedIndex;

        } catch (Exception e) {
            Log.e("Exception", e.getMessage());
        }

        holder.tv_lijishare_btn_no.setVisibility(View.GONE);
//        holder.tv_lijishare_btn.setVisibility(View.VISIBLE);
        for (int s = 0; s < Contig.ShareList.size(); s++) {
            if (list.get(position).getId().equals(Contig.ShareList.get(s))) {
                holder.tv_lijishare_btn_no.setVisibility(View.VISIBLE);
                holder.tv_lijishare_btn.setVisibility(View.GONE);
                Log.e("5647","youbianhua          "+list.get(position).getId());
                return convertView;

            }
        }

        return convertView;
    }
    //普通二和一链接0
    private void initJDputong(String id){
        Map<String,String>map=new HashMap<String, String>();
        map.put("spuId",id);
        map.put("appid", AUniqueIdentifier.getDeviceId(context));
        map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        Log.e("京东二合一转链",ApiManager.BASE_NIUPAI_URL+"jd/getUrl"+"?spuId="+id+"&appId="+AUniqueIdentifier.getDeviceId(context)+"&token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getUrl").build().execute(new StringCallback() {

            @Override
            public void onError(com.squareup.okhttp.Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Log.e("fgdgfe",response);
                Gson gson=new Gson();
                JDlianjie jDlianjie = gson.fromJson(response, JDlianjie.class);
                datalisnajie = jDlianjie.getData();
                Log.e("kfjsdkghdfk", datalisnajie);

            }
        });

    }


    public void clearText(int position, CheckBox cb_checked) {
        for (int i = 0; i < checkedIndex.size(); i++) {
            if (checkedIndex.get(i) == position) {
                numbers.set(position, "");
                checkedIndex.remove(i);
                checkBox.remove(i);
                break;
            }
        }
        checkedNumber--;
        setText();
        numbers.set(position, "");
        cb_checked.setText("");
    }

    public void setText() {
        for (int i = 0; i < checkedIndex.size(); i++) {
            numbers.set(checkedIndex.get(i), (i + 1) + "");
            checkBox.get(i).setText(numbers.get(checkedIndex.get(i)));

        }
    }


    class ViewHolder {
        private ImageView iv_item_share_todaySeletion_shopimage;
        private TextView tv_share_today_name;
        private TextView tv_share_today_yuanprice;
        private TextView tv_share_taday_redprice;
        private TextView tv_share_xianprice;
        private TextView tv_share_todaySeletion_yiqiangnum;
        private TextView tv_lijishare_btn;
        public TextView tv_lijishare_btn_no;
        public CheckBox cb_checked;
        private ImageView iv_speclia_jdOryh;
        private LinearLayout ll_details_go;
        private TextView tv_lijishare_btn_specila_pt;

    }


}
class SpecialListViewAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<SpecialBean.DataBean.ListBean> list;
    private IWXAPI api;
    ArrayList<String> arrayList;
    private List<Boolean> isChecked;    //每个条目是否为选中
    private List<String> numbers;       //每个条目应显示的数字
    private List<Integer> checkedIndex;   //保存选中的下标
    private List<CheckBox> checkBox;      //保存选中的checkBox
    private int maxChecked = 9;       //最多选中几个
    private int checkedNumber = 0;    //选中的个数
    //        private int length = list.size();  //条目的总长
    ArrayList<String> idlist;

    ArrayList<Integer> a = new ArrayList<>();
    int aa = 0;
    private JDlianjie jDlianjiebean;
    private String datalisnajie;
    private int location;
    private String datayouhui;

    public SpecialListViewAdapter(Context context, List<SpecialBean.DataBean.ListBean> list) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.list = list;
        this.idlist = idlist;
// 通过WXAPIFactory工厂，获取IWXAPI的实例
        api = WXAPIFactory.createWXAPI(context, Constants.WX_APPID);
        api.registerApp(Constants.WX_APPID);
        arrayList = new ArrayList<String>();
        isChecked = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            isChecked.add(false);
        }
        numbers = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            numbers.add("");
        }
        checkedIndex = new ArrayList<>();
        checkBox = new ArrayList<>();

    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public List<SpecialBean.DataBean.ListBean> getList() {
        return list;
    }

    public SpecialListViewAdapter setList(List<SpecialBean.DataBean.ListBean> list) {
        this.list = list;
        return this;
    }

    int ds = 0;

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.special_listview_item, null);
            holder = new ViewHolder();
            holder.itme_speclialist_vertical_imge = (ImageView) convertView.findViewById(R.id.itme_speclialist_vertical_imge);
            holder.itme_speclialist_vertical_Name = (TextView) convertView.findViewById(R.id.itme_speclialist_vertical_Name);
            holder.itme_speclialist_price = (TextView) convertView.findViewById(R.id.itme_speclialist_price);
            holder.tv_share_taday_redprice = (TextView) convertView.findViewById(R.id.itme_speclialist_couponMoney);
            holder.itme_speclialist_discountprice = (TextView) convertView.findViewById(R.id.itme_speclialist_discountprice);
//            holder.itme_speclialist_totalSales = (TextView) convertView.findViewById(R.id.itme_speclialist_totalSales);
            holder.tv_speclialist_lijifenxiang = (TextView) convertView.findViewById(R.id.tv_speclialist_lijifenxiang);
            holder.tv_speclialist_lijifenxiang_no = (TextView) convertView.findViewById(R.id.tv_speclialist_lijifenxiang_no);
            holder.itme_speclialist_vertical_CheckBox = (CheckBox) convertView.findViewById(R.id.itme_speclialist_vertical_CheckBox);
            holder.iv_speclialist_jdOryh= (ImageView) convertView.findViewById(R.id.iv_speclialist_jdOryh);
            holder.ll_details_list_go= (LinearLayout) convertView.findViewById(R.id.ll_details_list_go);
            holder.tv_speclialist_lijifenxiang_pt= (TextView) convertView.findViewById(R.id.tv_speclialist_lijifenxiang_pt);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //解决RecyclerView和checkBox问题
        holder.itme_speclialist_vertical_CheckBox.setTag(position);
        if (Specialactivity.hmap.containsKey(position)) {
            holder.itme_speclialist_vertical_CheckBox.setChecked(TodaysSelectionFragment.hmap.get(position));
        } else {
            holder.itme_speclialist_vertical_CheckBox.setChecked(false);//true or false 都可以，看实际需求
        }

        final SpecialBean.DataBean.ListBean bean = list.get(position);
        Log.e("数据", "positionLIST=========" + bean);
        UtilsImage.uploadimageview(holder.itme_speclialist_vertical_imge, bean.getMainImageUrl(), "", context);
        holder.itme_speclialist_vertical_Name.setText("\t\t\t\t" + bean.getGoodsName());
        holder.itme_speclialist_price.setText("¥" + bean.getPrice());
        holder.tv_share_taday_redprice.setText("降" + bean.getCouponMoney()+"元");
        holder.itme_speclialist_discountprice.setText("" + bean.getConPrice());

//        holder.itme_speclialist_totalSales.setText( bean.getTotalSales());
        if( list.get(position).getWlCommission()==0|| list.get(position).getWlCommission()==0.0|| list.get(position).getWlCommission()==0.00){
            holder.tv_speclialist_lijifenxiang.setText("立即分享");
            holder.tv_speclialist_lijifenxiang_no.setText("立即分享赚");
        }else {
            holder.tv_speclialist_lijifenxiang.setText("分享赚 ¥" + bean.getWlCommission());
            holder.tv_speclialist_lijifenxiang_no.setText("分享赚 ¥" + bean.getWlCommission());
        }
        holder.tv_speclialist_lijifenxiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShopYouhuiShareActivity.class);
                intent.putExtra("id", bean.getId());
                context.startActivity(intent);
                holder.tv_speclialist_lijifenxiang_no.setVisibility(View.VISIBLE);
                holder.tv_speclialist_lijifenxiang.setVisibility(View.GONE);

            }
        });
        if(SPUtils.getInstance().getString(SPConstants.KEY_ISSTORE).equals("1")){
            holder.itme_speclialist_vertical_CheckBox.setVisibility(View.VISIBLE);
            holder.tv_speclialist_lijifenxiang_pt.setVisibility(View.GONE);
            holder.tv_speclialist_lijifenxiang.setVisibility(View.VISIBLE);

        }else{
            holder.itme_speclialist_vertical_CheckBox.setVisibility(View.GONE);
            holder.tv_speclialist_lijifenxiang_pt.setVisibility(View.VISIBLE);
            holder.tv_speclialist_lijifenxiang.setVisibility(View.GONE);
        }
        if(bean.getSpuPlatform().equals("jd")){
            holder.iv_speclialist_jdOryh.setImageResource(R.drawable.jingdong);
        }else if(bean.getSpuPlatform().equals("yh")){
            holder.iv_speclialist_jdOryh.setImageResource(R.drawable.youhui);
        }
        holder.ll_details_list_go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                location = position;
                if (bean.getSpuPlatform().equals("yh")){
                    Intent intent=new Intent(context,Red_PacketActivity.class);
                    intent.putExtra("shopid",bean.getId());
                    intent.putExtra("typex","yh");
                    context.startActivity(intent);
                } else {
                    if (bean.getSpuPlatform().equals("jd")) {
                        if ("".equals(bean.getCouponMoney()+"")) {
                            initJDputong(bean.getId());
                            if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                try {
                                    KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                } catch (KeplerBufferOverflowException e) {
                                    e.printStackTrace();
                                }

                            }else {
                                final LoginListener mLoginListener = new LoginListener() {
                                    @Override
                                    public void authSuccess(Object token) {
                                        // TODO Auto-generated method stub
                                        Toast.makeText(context, token + "", Toast.LENGTH_SHORT).show();
                                        //                showToken();

                                        if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                            try {
                                                KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                            } catch (KeplerBufferOverflowException e) {
                                                e.printStackTrace();
                                            }
                                        }

                                    }

                                    @Override
                                    public void authFailed(int errorCode) {
                                        // TODO Auto-generated method stub
                                        switch (errorCode) {
                                            case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                            case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                            default:
                                                break;
                                        }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                        Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                    }
                                };
                                KeplerApiManager.getWebViewService().login((Activity) context, mLoginListener);
                            }
//                            Intent intent = new Intent(context, HtmlActivity.class);
//                            intent.putExtra("data", datalisnajie);
//                            intent.putExtra("shopid", bean.getId());
//                            context.startActivity(intent);
                        }
                        if (""!=bean.getCouponMoney()+""){
                            if (bean.getCouponMoney()==0.0){
                                Map<String,String>map=new HashMap<>();
                                map.put("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId",bean.getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(context));
                                Log.e("优惠二和一链接接口",ApiManager.BASE_NIUPAI_URL+"jd/getConUrl"+"?token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&spuId="+bean.getId()+"&appid="+AUniqueIdentifier.getDeviceId(context));
                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getConUrl").build().execute(new StringCallback() {


                                    @Override
                                    public void onError(com.squareup.okhttp.Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        Log.e("优惠二和一数据",response);
                                        Gson gson=new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            Intent intent=new Intent(context,JDred_packetActivity.class);
                                            intent.putExtra("shopid",bean.getId());
                                            context.startActivity(intent);
                                        }
                                    }
                                });

                            }else {
                                Map<String,String>map=new HashMap<>();
                                map.put("token",SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
                                map.put("spuId",bean.getId());
                                map.put("appid", AUniqueIdentifier.getDeviceId(context));

                                OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getConUrl").build().execute(new StringCallback() {


                                    @Override
                                    public void onError(com.squareup.okhttp.Request request, Exception e) {

                                    }

                                    @Override
                                    public void onResponse(String response) {
                                        Log.e("优惠二和一数据",response);
                                        Gson gson=new Gson();
                                        jDlianjiebean = gson.fromJson(response, JDlianjie.class);
                                        datayouhui = jDlianjiebean.getData();
                                        if (jDlianjiebean.getCode().equals("10000")) {
                                            if (jDlianjiebean.getData()!=null){
                                                if(KeplerApiManager.getWebViewService().isKeplerLogined()){
                                                    try {
                                                        KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                    } catch (KeplerBufferOverflowException e) {
                                                        e.printStackTrace();
                                                    }

                                                }else {
                                                    final LoginListener mLoginListener = new LoginListener() {
                                                        @Override
                                                        public void authSuccess(Object token) {
                                                            // TODO Auto-generated method stub
                                                            Toast.makeText(context, token + "", Toast.LENGTH_SHORT).show();
                                                            //                showToken();

                                                            if (KeplerApiManager.getWebViewService().isKeplerLogined()) {
                                                                try {
                                                                    KeplerApiManager.getWebViewService().openJDUrlWebViewPage(jDlianjiebean.getData() + "&userid" + SPUtils.getInstance().getString(SPConstants.KEY_USERID), "kepler_customer_Info");
                                                                } catch (KeplerBufferOverflowException e) {
                                                                    e.printStackTrace();
                                                                }
                                                            }

                                                        }

                                                        @Override
                                                        public void authFailed(int errorCode) {
                                                            // TODO Auto-generated method stub
                                                            switch (errorCode) {
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_Init:// 初始化失败 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_InitIng:// 初始化没有完成 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_openH5authPageURLSettingNull://跳转url // 为null break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_getTokenErr:// 获取失败(OAuth授权之后，获取cookie过程出错) break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_User_Cancel:// 用户取消 break;
                                                                case KeplerApiManager.KeplerApiManagerLoginErr_AuthErr_ActivityOpen://打开授权页面失败 break;
                                                                default:
                                                                    break;
                                                            }
//                Toast.makeText(AllOrderActivity.this, errorCode + ":authFailed", Toast.LENGTH_SHORT).show();
                                                            Log.e("jdSHOUQUAN", errorCode + ":authFailed");
                                                        }
                                                    };
                                                    KeplerApiManager.getWebViewService().login((Activity) context, mLoginListener);
                                                }
//                                                Intent intent = new Intent(context, HtmlActivity.class);
//                                                intent.putExtra("shopid", bean.getId());
//                                                intent.putExtra("data", datayouhui);
//                                                context.startActivity(intent);

                                            }
                                        }
                                    }
                                });


                            }
                        }


                    }
                }

            }

        });
        try {


            //  不要动
            holder.itme_speclialist_vertical_CheckBox.setChecked(isChecked.get(position));
            holder.itme_speclialist_vertical_CheckBox.setText(numbers.get(position));
            holder.itme_speclialist_vertical_CheckBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    boolean check;
                    if (checkedNumber < maxChecked) {
                        if (!isChecked.get(position)) {
                            checkedIndex.add(position);
                            checkBox.add(holder.itme_speclialist_vertical_CheckBox);
                            checkedNumber++;
                            setText();
                        } else {
                            clearText(position, holder.itme_speclialist_vertical_CheckBox);
                        }
                        check = !isChecked.get(position);
                    } else {
                        if (checkedNumber == maxChecked && isChecked.get(position)) {
                            clearText(position, holder.itme_speclialist_vertical_CheckBox);
                        } else {
                            Toast.makeText(context, "最多只能选" + maxChecked + "个", Toast.LENGTH_SHORT).show();
                        }
                        check = false;
                    }
                    isChecked.set(position, check);
                    holder.itme_speclialist_vertical_CheckBox.setChecked(isChecked.get(position));
                }
            });

            Contig.checkedIndexlist = checkedIndex;
//                //这个就是那个id  idlist集合
//                if(idlist.size()>0){
//                    for (int i=0;i<idlist.size();i++){
//                        Log.e("数据Toady",position+"aaa"+idlist.get(i));
//                        if(idlist.get(i).equals(bean.getId())){
//                            aa=1;
//                            Log.e("数据Toady","aaaaaa"+aa);
//                        }else{
//                            aa=0;
//                            Log.e("数据Toady","aaaaa"+aa);
//                        }
//
//                    }
//                    a.add(aa);
//                    Log.e("数据Toady","aaaaaa"+aa);
//                }
        } catch (Exception e) {
            Log.e("Exception", e.getMessage());
        }

//                if(aa==1){
//                    holder.tv_lijishare_btn_no.setVisibility(View.VISIBLE);
//                    holder.tv_lijishare_btn.setVisibility(View.GONE);
//                }else{
//                    holder.tv_lijishare_btn_no.setVisibility(View.GONE);
//                    holder.tv_lijishare_btn.setVisibility(View.VISIBLE);
//                }
        holder.tv_speclialist_lijifenxiang_no.setVisibility(View.GONE);
//        holder.tv_speclialist_lijifenxiang.setVisibility(View.VISIBLE);
        for (int s = 0; s < Contig.ShareListlv.size(); s++) {
            if (list.get(position).getId().equals(Contig.ShareListlv.get(s))) {
                holder.tv_speclialist_lijifenxiang_no.setVisibility(View.VISIBLE);
                holder.tv_speclialist_lijifenxiang.setVisibility(View.GONE);
                Log.e("5647","youbianhua          "+list.get(position).getId());
                return convertView;

            }
        }

        return convertView;
    }

    //普通二和一链接0
    private void initJDputong(String id){
        Map<String,String>map=new HashMap<String, String>();
        map.put("spuId",id);
        map.put("appid", AUniqueIdentifier.getDeviceId(context));
        map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        Log.e("京东二合一转链",ApiManager.BASE_NIUPAI_URL+"jd/getUrl"+"?spuId="+id+"&appId="+AUniqueIdentifier.getDeviceId(context)+"&token="+ SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        OkHttpUtils.post().params(map).url(ApiManager.BASE_NIUPAI_URL+"jd/getUrl").build().execute(new StringCallback() {

            @Override
            public void onError(com.squareup.okhttp.Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Log.e("fgdgfe",response);
                Gson gson=new Gson();
                JDlianjie jDlianjie = gson.fromJson(response, JDlianjie.class);
                datalisnajie = jDlianjie.getData();
                Log.e("kfjsdkghdfk", datalisnajie);

            }
        });

    }

    public void clearText(int position, CheckBox cb_checked) {
        for (int i = 0; i < checkedIndex.size(); i++) {
            if (checkedIndex.get(i) == position) {
                numbers.set(position, "");
                checkedIndex.remove(i);
                checkBox.remove(i);
                break;
            }
        }
        checkedNumber--;
        setText();
        numbers.set(position, "");
        cb_checked.setText("");
    }

    public void setText() {
        for (int i = 0; i < checkedIndex.size(); i++) {
            numbers.set(checkedIndex.get(i), (i + 1) + "");
            checkBox.get(i).setText(numbers.get(checkedIndex.get(i)));

        }
    }


    class ViewHolder {
        private ImageView itme_speclialist_vertical_imge;
        private TextView itme_speclialist_vertical_Name;
        private TextView itme_speclialist_price;
       private TextView tv_share_taday_redprice;
        private TextView itme_speclialist_discountprice;
        private TextView itme_speclialist_totalSales;
        private TextView tv_speclialist_lijifenxiang;
        public TextView tv_speclialist_lijifenxiang_no;
        public CheckBox itme_speclialist_vertical_CheckBox;
        private ImageView iv_speclialist_jdOryh;
        private LinearLayout ll_details_list_go;
        private TextView tv_speclialist_lijifenxiang_pt;

    }


}


